/* 
 * Cashbox is the legal property of its developers, whose names are listed in the copyright file included
 * with this source distribution.
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program; if not,
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#import "CBMixedStateSwitchCell.h"

@implementation CBMixedStateSwitchCell

- (id)initWithCoder:(NSCoder *)aDecoder {
	if (self = [super initWithCoder:aDecoder]) {
		[self setButtonType:NSSwitchButton];
		[self setAllowsMixedState:[super allowsMixedState]];
		[super setAllowsMixedState:YES];
	}
	return self;
}

- (id)init {
	if (self = [super init]) {
		[self setButtonType:NSSwitchButton];
		[self setAllowsMixedState:YES];
		[super setAllowsMixedState:YES];
	}
	return self;
}

- (void)setAllowsMixedState:(BOOL)flag {
	allowsMixedState = flag;
}

- (void)setNextState {
	int state = [self state];
	if (state == NSOffState) {
		if (allowsMixedState || optionKeyPressed) { [self setState:NSMixedState]; }
		else { [self setState:NSOnState]; }
	} else {
		[super setNextState];
	}
}

- (BOOL)trackMouse:(NSEvent *)theEvent
			inRect:(NSRect)cellFrame
			ofView:(NSView *)controlView
	  untilMouseUp:(BOOL)flag {

	settingByClick = TRUE;
	optionKeyPressed = ([theEvent modifierFlags] & NSAlternateKeyMask) == NSAlternateKeyMask;

	BOOL retVal = [super trackMouse:theEvent inRect:cellFrame ofView:controlView untilMouseUp:flag];
	
	optionKeyPressed = FALSE;
	settingByClick = FALSE;
	
	return retVal;
}

@end
